package MyDaily.Servlet.page;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import MyDaily.dao.daily.Deletedaily;

/**
 * Servlet implementation class DeleteDaily
 */
@WebServlet("/DeleteDaily")
public class DeleteDaily extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DeleteDaily() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 设置请求，响应的字符集
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		// sid为主界面绑定数据的变量名
		int id = Integer.parseInt(request.getParameter("sid"));
		// 调用删除方法
		int i = Deletedaily.delete(id);
		if (i > 0) {
			request.getRequestDispatcher("PageSer").forward(request, response);
		}else {
			request.setAttribute("error", "删除学生信息失败");
			request.getRequestDispatcher("PageServlet").forward(request, response);
		}
	}

}
